home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / HD / SmartFileSystem / V1.58 / Sources / SFSformat / sfsformat.c
Encoding:
C/C++ Source or Header  |  1999-01-24  |  3.1 KB  |  116 lines

  1. #include <dos/dos.h>
  2. #include <dos/dosextens.h>
  3. #include <proto/dos.h>
  4. #include <proto/exec.h>
  5. #include <utility/tagitem.h>
  6.  
  7. #include "/fs/packets.h"
  8.  
  9. static const char version[]={"\0$VER: SFSformat 1.0 " __AMIGADATE__ "\r\n"};
  10.  
  11. LONG main() {
  12.   struct RDArgs *readarg;
  13.   UBYTE template[]="DEVICE=DRIVE/A/K,NAME/A/K,CASESENSITIVE/S,NORECYCLED/S,SHOWRECYCLED/S\n";
  14.  
  15.   struct {char *device;
  16.           char *name;
  17.           ULONG casesensitive;
  18.           ULONG norecycled;
  19.           ULONG showrecycled;} arglist={NULL};
  20.  
  21.   if((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))!=0) {
  22.     if((readarg=ReadArgs(template,(LONG *)&arglist,0))!=0) {
  23.       struct MsgPort *msgport;
  24.       struct DosList *dl;
  25.       UBYTE *devname=arglist.device;
  26.  
  27.       while(*devname!=0) {
  28.         if(*devname==':') {
  29.           *devname=0;
  30.           break;
  31.         }
  32.         devname++;
  33.       }
  34.  
  35.       dl=LockDosList(LDF_DEVICES|LDF_READ);
  36.       if((dl=FindDosEntry(dl,arglist.device,LDF_DEVICES))!=0) {
  37.         BPTR input;
  38.         LONG errorcode=0;
  39.  
  40.         input=Input();
  41.         msgport=dl->dol_Task;
  42.         UnLockDosList(LDF_DEVICES|LDF_READ);
  43.  
  44.         PutStr("Press RETURN to begin formatting or CTRL-C to abort: ");
  45.         Flush(Output());
  46.  
  47.         if(IsInteractive(input)!=DOSFALSE) {
  48.           for(;;) {
  49.             if((WaitForChar(input,100)==DOSTRUE)) {
  50.               if(errorcode==0 && (errorcode=DoPkt(msgport,ACTION_INHIBIT,DOSTRUE,0,0,0,0))!=DOSFALSE) {
  51.  
  52.                 {
  53.                   struct TagItem tags[5];
  54.                   struct TagItem *tag=tags;
  55.  
  56.                   tag->ti_Tag=ASF_NAME;
  57.                   tag->ti_Data=(ULONG)arglist.name;
  58.                   tag++;
  59.  
  60.                   if(arglist.casesensitive!=0) {
  61.                     tag->ti_Tag=ASF_CASESENSITIVE;
  62.                     tag->ti_Data=TRUE;
  63.                     tag++;
  64.                   }
  65.  
  66.                   if(arglist.norecycled!=0) {
  67.                     tag->ti_Tag=ASF_NORECYCLED;
  68.                     tag->ti_Data=TRUE;
  69.                     tag++;
  70.                   }
  71.  
  72.                   if(arglist.showrecycled!=0) {
  73.                     tag->ti_Tag=ASF_SHOWRECYCLED;
  74.                     tag->ti_Data=TRUE;
  75.                     tag++;
  76.                   }
  77.  
  78.                   if((errorcode=DoPkt(msgport, ACTION_SFS_FORMAT, (LONG)&tags, 0, 0, 0, 0))==DOSFALSE) {
  79.                     PrintFault(IoErr(),"error while initializing the drive");
  80.                   }
  81.                 }
  82.  
  83.                 DoPkt(msgport,ACTION_INHIBIT,DOSFALSE,0,0,0,0);
  84.               }
  85.               else {
  86.                 PrintFault(IoErr(),"error while locking the drive");
  87.               }
  88.               break;
  89.             }
  90.             else if(SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
  91.               PutStr("\n***Break\n");
  92.               break;
  93.             }
  94.           }
  95.  
  96.           while(WaitForChar(input,0)==DOSTRUE) {
  97.             FGetC(input);
  98.           }
  99.         }
  100.       }
  101.       else {
  102.         VPrintf("Unknown device %s\n",&arglist.device);
  103.         UnLockDosList(LDF_DEVICES|LDF_READ);
  104.       }
  105.  
  106.       FreeArgs(readarg);
  107.     }
  108.     else {
  109.       PutStr("wrong args!\n");
  110.     }
  111.  
  112.     CloseLibrary((struct Library *)DOSBase);
  113.   }
  114.   return(0);
  115. }
  116.